﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UI
{
        
    class MainForm_EventHandler
    {
       
        public static int SelectedIndex;
        
        
        public static WcfServiceRef.SmartHouseWCFClient client;

        public  static WcfServiceRef.SmartHouseDataSet recievedDataSet;

       

        public MainForm_EventHandler()
        {
            client = new WcfServiceRef.SmartHouseWCFClient();
            recievedDataSet = client.Get();
            
        }
        
       


        public void ShowFormAddVariables()
        {
            Add_Edit_Variable add_variable = new Add_Edit_Variable();
            add_variable.Show();
        }

        public void ShowFormAddEvents()
        {
            Add_Edit_Event add_event = new Add_Edit_Event();
            add_event.Show();
        }

        public void ShowFormAddOperations()
        {
            Add_Edit_Operation add_operation = new Add_Edit_Operation();
            add_operation.Show();
        }

        public void ShowFormAddBindings()
        {
            Add_Edit_Binding add_binding = new Add_Edit_Binding();
            add_binding.Show();
        }

        public void TabIndexChanged(int newIndex)
        {
            SelectedIndex = newIndex;
        }

        public void ShowFormEditVariables()
        {

            Add_Edit_Variable edit_variable = new Add_Edit_Variable(recievedDataSet.Variables.FindByVariableId(MainForm.selectedRow + 1).Name,
                                                                    recievedDataSet.Variables.FindByVariableId(MainForm.selectedRow + 1).Description,
                                                                    recievedDataSet.Variables.FindByVariableId(MainForm.selectedRow = 1).InitialValue);                                       
        }

        public void ShowFormEditEvents()
        {
            Add_Edit_Event edit_event = new Add_Edit_Event(recievedDataSet.Events.FindByEventId(MainForm.selectedRow + 1).Name,
                                                           recievedDataSet.Events.FindByEventId(MainForm.selectedRow + 1).Description);
        }

        public void ShowFormEditOperations()
        {
            
        }

        public void ShowFormEditBindings()
        {

        }

        public static void DeleteVariable(int selectedRow)
        {
            recievedDataSet.Variables.RemoveVariablesRow(recievedDataSet.Variables.FindByVariableId(selectedRow+1));
           
            client.Set(recievedDataSet);
        }

        public static void AddVariable(string name, string description, string InitValue)
        {
            recievedDataSet.Variables.AddVariablesRow(name, description, InitValue, "int");
        }
    }
}
